home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / fortify.lha / fortify.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-03  |  2.8 KB  |  78 lines

  1. #ifndef __FORTIFY_H__
  2. #define __FORTIFY_H__
  3. /*
  4.  * FILE:
  5.  *   fortify.h
  6.  *
  7.  * DESCRIPTION:
  8.  *     Header file for fortify.c - A fortified shell for malloc, realloc, 
  9.  *   calloc & free
  10.  *
  11.  * WRITTEN:
  12.  *   spb 29/4/94
  13.  *
  14.  * VERSION:
  15.  *   1.0 29/4/94
  16.  */
  17. #include <stdlib.h>
  18.  
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22.  
  23. typedef void (*OutputFuncPtr)(char *);
  24.  
  25. void *Fortify_malloc(size_t size, char *file, unsigned long line);
  26. void *Fortify_realloc(void *ptr, size_t new_size, char *file, unsigned long line);
  27. void *Fortify_calloc(size_t num, size_t size, char *file, unsigned long line);
  28. void  Fortify_free(void *uptr, char *file, unsigned long line);
  29.  
  30. int   Fortify_OutputAllMemory(char *file, unsigned long line);
  31. int   Fortify_CheckAllMemory(char *file, unsigned long line);
  32. int   Fortify_CheckPointer(void *uptr, char *file, unsigned long line);
  33. int   Fortify_Disable(char *file, unsigned long line);
  34. int   Fortify_SetMallocFailRate(int Percent);
  35. int   Fortify_EnterScope(char *file, unsigned long line);
  36. int   Fortify_LeaveScope(char *file, unsigned long line);
  37. int   Fortify_DumpAllMemory(int scope, char *file, unsigned long line);
  38.  
  39. typedef void (*Fortify_OutputFuncPtr)(const char *);
  40. Fortify_OutputFuncPtr Fortify_SetOutputFunc(Fortify_OutputFuncPtr Output);
  41.  
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45.  
  46. #ifndef __FORTIFY_C__ /* Only define the macros if we're NOT in fortify.c */
  47.  
  48. #ifdef FORTIFY /* Add file and line information to the fortify calls */
  49.  
  50. #define malloc(size)                  Fortify_malloc(size, __FILE__, __LINE__)
  51. #define realloc(ptr,new_size)         Fortify_realloc(ptr, new_size, __FILE__, __LINE__)
  52. #define calloc(num,size)              Fortify_calloc(num, size, __FILE__, __LINE__)
  53. #define free(ptr)                     Fortify_free(ptr, __FILE__, __LINE__)
  54.  
  55. #define Fortify_OutputAllMemory()     Fortify_OutputAllMemory(__FILE__, __LINE__)
  56. #define Fortify_CheckAllMemory()      Fortify_CheckAllMemory(__FILE__, __LINE__)
  57. #define Fortify_CheckPointer(ptr)     Fortify_CheckPointer(ptr, __FILE__, __LINE__)
  58. #define Fortify_Disable()             Fortify_Disable(__FILE__, __LINE__)
  59. #define Fortify_EnterScope()          Fortify_EnterScope(__FILE__, __LINE__)
  60. #define Fortify_LeaveScope()          Fortify_LeaveScope(__FILE__, __LINE__)
  61. #define Fortify_DumpAllMemory(s)      Fortify_DumpAllMemory(s,__FILE__, __LINE__)
  62.  
  63. #else /* FORTIFY Define the special fortify functions away to nothing */
  64.  
  65. #define Fortify_OutputAllMemory()     0
  66. #define Fortify_CheckAllMemory()      0
  67. #define Fortify_CheckPointer(ptr)     1
  68. #define Fortify_Disable()             1
  69. #define Fortify_SetOutputFunc()       0
  70. #define Fortify_SetMallocFailRate(p)  0
  71. #define Fortify_EnterScope()          0
  72. #define Fortify_LeaveScope()          0
  73. #define Fortify_DumpAllMemory(s)      0
  74.  
  75. #endif /*   FORTIFY     */
  76. #endif /* __FORTIFY_C__ */
  77. #endif /* __FORTIFY_H__ */
  78.